/*
 * @Author: wangjq4214
 * @Date: 2022-04-16 23:39:30
 * @LastEditTime: 2022-06-05 17:35:36
 * @LastEditors: wangjq4214
 */
package main

import (
	"flag"
)

var (
	ip           = flag.String("ip", "", "The self ip, if not point it will use udp to get a ip")
	port         = flag.Int("port", 50052, "The server port")
	addr         = flag.String("addr", "localhost:50051", "The address to connect to")
	cpuTotal     = flag.Int("cpu-total", 16, "The total of CPU")
	cpuMax       = flag.Int("cpu-max", 8, "The max CPU of task")
	storageTotal = flag.Int("storage-total", 1024, "The total of storage")
	timeLength   = flag.Int("time", 60, "The max running time")
)

func main() {
	flag.Parse()

	newChan := make(chan *[]Task, 3)
	commitChan := make(chan Task, 3)
	finishChan := make(chan Task, 3)
	status := NewStatus(*cpuTotal, *cpuMax, *storageTotal, *timeLength)
	register := NewRegister(*addr, *ip, *port, status, finishChan, newChan)
	server := NewServer(commitChan, newChan)
	grpcServer := NewGRPCServe(server, *port)
	runner := NewRunner(commitChan, finishChan, status)

	go register.Beat()
	go register.Report()
	go runner.SaveTask()
	go runner.RunTask()
	go grpcServer.Lis()

	wait := make(chan struct{})
	<-wait
}
